package com.gongj.fshe.controller;

import com.gongj.fshe.dto.BankCardDTO;
import com.gongj.fshe.dto.IdCardDTO;
import com.gongj.fshe.dto.UserInfoDTO;
import com.gongj.fshe.utils.CheckUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/api")
public class TestController {

    @PostMapping(value = "/saveUser")
    private String saveUser(@RequestBody UserInfoDTO req){
        //效验 用户信息
        String check = CheckUtil.checkObjNull(req, Arrays.asList("email","userId", "name", "cardDTOList", "idCardDTO"));
        if(StringUtils.hasLength(check)){
            return check;
        }
        //效验 用户信息内的 银行卡列表
        List<BankCardDTO> cardDTOList = req.getCardDTOList();
        String check2 = CheckUtil.checkArrayNull(cardDTOList, Arrays.asList("cardNumber", "bankName"),"cardDTOList");
        if(StringUtils.hasLength(check2)){
            return check2;
        }
        //效验 用户信息内的 身份证信息
        IdCardDTO idCardDTO = req.getIdCardDTO();
        String check3 = CheckUtil.checkObjNull(idCardDTO, Arrays.asList("idNumber", "validity"));
        if(StringUtils.hasLength(check3)){
            return check3;
        }
        return "成功";
    }
}
